#!/bin/bash
#
# quickbuild:8811,8812 
# description : publish $1.war 
# 2013-4-7 pope add
war_t=$1
war_name=$1_tomcat7
echo "------------------------------------publish $war_name"
war_path=/home/work/server/$war_name
# stop tomcat
source /home/work/war_ftp/use_test.sh #import test use shell
stoptomcat ${war_t} ${war_path}/bin
	 ##test test code using
         ###echo "test test code using"
         ###sh ${war_path}/bin/startup.sh
         ###wait
	# test stop
	#echo "----------stoptomcat : "$?
	whetherok "${war_path}"
	res_whetherok=$?
	if [ 1 == ${res_whetherok} ];then
		echo "-----------------------------------------ERR STOP TOMCAT--------------------------------------"
		ps aux|grep ${war_t}
		exit 1
	else
		echo '${res_whetherok} :'${res_whetherok}
	fi
#del work
rm -rf ${war_path}/work 
#del old
rm -rf ${war_path}/webapps/${war_t}
echo $?
	#test del old 
  	whetherdel ${war_path}/webapps/ ${war_t}
	testdel=$?
	if [ 1 == ${testdel} ];then
		echo "------------------------------------------ERR DEL ---------------------------------"
		ls -all ${war_path}/webapps/ |grep -E "${war_t}\$"
		exit 1
	fi 
# copy new & tar
mkdir ${war_path}/webapps/${war_t}
unzip  /opt/test_ftp/${war_t}* -d /${war_path}/webapps/${war_t}/ >/dev/null 2>&1 &
wait
	#test new PS:linux.map[?]<du> new war test
	d=`date +%m-%d` # [next] get war.date
	whethernew ${war_path}/webapps/${war_t} $d 
	resnew=$?
	if [ 1 == ${resnew} ];then
		echo "------------------------------------------ERR NEW------------------------------------"
		ls -all ${war_path}/webapps/${war_t}|grep -c $d
		echo "today files <6"
		exit 1
	fi
# change config
changefile ${war_path}/webapps/${war_t}
	#test change config
# start tomcat
# test new
sh ${war_path}/bin/startup.sh 
# del war
rm -rf /opt/test_ftp/$war_t*
